﻿using System;
using System.Collections.Generic;
using System.Text;
using TSVNAddin.TSVN;
using EnvDTE;
using EnvDTE80;

namespace TSVNAddin.Core
{
	public class GenericPathCommand : ICommand
	{
		private readonly TortoiseProcExecutor _TortoiseProcExecutor;
		private readonly RepositoryPathFinder _RepositoryPathFinder;
		private TortoiseProcCommandType _TortoiseCommandType;
		private TortoiseProcArgumentType[] _TortoiseArguments;

		public GenericPathCommand(TortoiseProcExecutor tortoiseProcExecutor, RepositoryPathFinder repositoryPathFinder, TortoiseProcCommandType tortoiseCommandType, params TortoiseProcArgumentType[] tortoiseArguments)
		{
			_TortoiseProcExecutor = tortoiseProcExecutor;
			_RepositoryPathFinder = repositoryPathFinder;
			_TortoiseCommandType = tortoiseCommandType;
			_TortoiseArguments = tortoiseArguments;
		}

		public void Execute(DTE2 applicationObject)
		{
			string repositoryPath = _RepositoryPathFinder.FindRootPath(applicationObject);
			_TortoiseProcExecutor.Exec(_TortoiseCommandType, repositoryPath, _TortoiseArguments);
		}

		public vsCommandStatus QueryStatus()
		{
			return (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
		}
	}
}
